<?php

if (!defined('TOBBIVM'))
	header('location:/template/notrepassing.php');
/**
 * This file is part of TobbiVMShop.
 *
 * TobbiVMShop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TobbiVMShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TobbiVMShop.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * create shipping edit page
 * used from shipping.page.php
 * get: shipping.edit.tpl.php
 *
 * @version    $Id$
 * @package    TobbiVM-Shop
 * @copyright  Copyright (C) 2012
 * @author     Norbert Gebert
 * @license    GPL3
 */
db::getInstance()->where('shipping_id', $refValidate->cleanslash($_GET['id']));
$result = db::getInstance()->getOne('shipping');

if (db::getInstance()->count <= 0)
{
	message::setErrorRow(_('Databaseerror! - Contact Admin!'), true);
}
else
{
	$refPage->assign('page_title', _('Edit shipping'));

	$refPage->assign('id', _('Shipping-Id') . '= ' . $result['shipping_id']);

	$refPage->assign('name', _('Shipping-name'));
	$refPage->assign('namex', $result['shipping_name']);
	$refPage->assign('namexHelp', help('shippingname', $page));

	$refPage->assign('value', _('Fixed costs in ') . CURRENCY);
	$refPage->assign('valuex', str_replace('.', ',', $result['shipping_value']));
	$refPage->assign('valuexHelp', help('shippingvalue', $page));

	$refPage->assign('order', _('Order'));
	$refPage->assign('orderx', $result['shipping_order']);
	$refPage->assign('orderxHelp', help('shippingorder', $page));

	$refPage->assign('active', _('Activ'));
	$activey = '<input type="checkbox" name="activex" id="activex" value="activex" ';

	if ($result['shipping_active'] === 0)
	{
		$activey .= '/>';
	}
	else
	{
		$activey .= 'checked />';
	}
	$refPage->assign('activex', $activey);
	$refPage->assign('activexHelp', help('shippingactive', $page));

	$refPage->assign('table', _('Table'));
	$refPage->assign('tablex', $result['shipping_table']);

	$refPage->assign('file', _('File'));
	$refPage->assign('filex', $result['shipping_file']);
	$refPage->assign('filexHelp', help('shippingfile', $page));

	// tax
	db::getInstance()->orderBy('tax_name', 'ASC');
	$tax_ids = db::getInstance()->get('tax');
	$taxy = array();
	
	foreach ($tax_ids as $tax_entry)
	{
		if ($tax_entry['tax_id'] === $result['shipping_tax_id'])
		{
			$taxy[] = array('taxValuex' => $tax_entry['tax_id'],
			 'taxNamex' => ($tax_entry['tax_value'] . '% - ' . $tax_entry['tax_name']),
			 'selectx' => 'selected="selected"');
		}
		else
		{
			$taxy[] = array('taxValuex' => $tax_entry['tax_id'],
			 'taxNamex' => ($tax_entry['tax_value'] . '% - ' . $tax_entry['tax_name']),
			 'selectx' => ' ');
		}
	}
	$refPage->assign('tax', _('Tax') . ': ');
	$refPage->assign('taxx', $taxy);
	$refPage->assign('taxxHelp', help('shippingtax', $page));

	$refPage->assign('Form_Start',
		'<form class="niceform fieldset" action="' .
		'index2.php?page=' . $page . '&sub=' . $subpage .
		'" method="post"><fieldset>');
	$refPage->assign('Form_End',
		'<input type="hidden" name="idx" value="' . $result['shipping_id'] . '">' .
		'</fieldset></form>');

	$refPage->assign('btn_save',
		'<input type="submit" name="submit" id="save" value="' .
		_('Save') . '" />');
	$refPage->assign('btn_abort',
		'<input type="submit" name="submit" id="abort" value="' .
		_('Cancel') . '" />');
	$refPage->assign('shippingPageHelp', help($result['shipping_file'], $page, TRUE));
	$refPage->assign('scripts',
		'<script type="text/javascript" src="' .
		'module/ckeditor/ckeditor.js"></script>');
	$refPage->addtpl('content', '/' . $page . '/' . $subpage . '.editor.tpl.php');
}
?>